# 主要是systemverilog 

snippet repeat      "repeat loop"
repeat(${1:Number})
begin
    ${2:/*code*/}
end
endsnippet

snippet while      "while loop"
while(${1:condition})
begin
    ${2:/*code*/}
end
endsnippet

snippet fopen    "open file"
integer ${1:name};
initial
begin
    $1 = $fopen("${2:file}.txt");
    $fmonitor($1, "%h %t", ${3:variable}, $time);
    $fclose($1);
end
endsnippet

#random
snippet random
${1:veriable} = ({$random} % ${2:2});
endsnippet

#strobe
snippet strobe
$strobe("${1:veriable} = 0${2:x}%${3:h}",$1);
endsnippet

#strobe
snippet monitor
$monitor($time,"${1:veriable} = 0${2:x}%${3:h}",$1);
endsnippet

#fdisplay, write data to file
snippet fdisplay "$fdisplay() function"
$fdisplay(${1:handle},"${2:veriable} = 0${3:x}%${4:h}",$2);
endsnippet


snippet fwrite    "write file"
integer ${1:in_handle};
initial
begin
    $1 = $fopen("{$2:in.txt}", "w");
end 
always @ (clk)
begin
    if(s_axis_tvalid & s_axis_tready)
        $fwrite($1, "%x", s_axis_tdata);
end
endsnippet


snippet display     "$display() function"
\$display("${1:format}", ${2:variable});
endsnippet


snippet forever     "forever"
forever
    #CLKPRIEOD  clk = ~clk;         //only use initial block
endsnippet


snippet interface_uart "use uart interface" b
uart_bfm #
(
    .BAUDRATE            (  ${1:115200}                         )
)
${2:ephemeris}_if ();
uart_drive #($1) $2_drive_h;

task generate_$2_data();
    automatic byte frame[] = new[21];
    for(int i = 0; i < 21; i = i + 1 )
    begin
        frame[i] = i + 1;
    end
    $2_drive_h.write(frame);
endtask

initial
begin
    $2_drive_h = new($2_if);
    #10us;
    generate_$2_data();
end

endsnippet

snippet clk     "generate clock"
reg                     ${1:clk} = 0;
always
    #(1s/${2:freq}/2) $1 = ~$1;
endsnippet

snippet rst "generate reset" 
reg                     ${1:rst} = 0;
initial
begin
    $1 = 0; #1us;
    $1 = 1; #1us; 
    $1 = 0; #1us; 
end
endsnippet

snippet delay "delay random time"
repeat($urandom_range(${1:3, 50})) 
    #1ns;
endsnippet

snippet queue   "queue"
${1:int} ${2:name}[$] ${3:= {3,4}};
endsnippet

snippet clocking    "clocking block"
clocking ${1:cb} @ (posedge clk);
input   #${2:time}  /*signal*/;
output  #${3:time}  /*signal*/;     // clk之后延迟time时间才会输出信号
endclocking
endsnippet

snippet fork "阻塞到所有子进程结束"
fork
    begin
    ${1:/*code_block1()*/}
    end
    begin
    /*code_block2()*/
    end
join
endsnippet

snippet fork_any "阻塞到任意一子进程结束"
fork
    begin
    ${1:/*code_block1()*/}
    end
    begin
    /*code_block2()*/
    end
join_any
endsnippet

snippet fork_none "所有进程并发执行"
fork
    begin
    ${1:/*code_block1()*/}
    end
    begin
    /*code_block2()*/
    end
join_none
endsnippet

snippet class   "base class"
class ${1:`!v expand('%:r')`};
    /*
     * 静态属性
     */
    function new(/*parameter*/);  // 需要赋初值的属性
        //this.x = x;
    endfunction
endclass
endsnippet

#######################################################################
######################   array          #################################
#######################################################################
snippet array_unpacked "unpacked array"
${1:type} name[${2:msb}:0];
endsnippet

snippet array_packed "packed array"
${1:type} [${2:msb}:0] name;
endsnippet

snippet array_min "return min element in the array"

endsnippet

snippet array_max ""

endsnippet

snippet array_sum ""

endsnippet

snippet array_and ""

endsnippet

snippet array_or ""

endsnippet

snippet array_xor ""

endsnippet

snippet array_reverse ""

endsnippet

snippet array_sort ""

endsnippet

snippet array_rsort ""

endsnippet
